<script setup>
  import { computed } from 'vue'
  import { NODE_TYPE_LABELS, NODE_TYPE_ROUTES } from '@/helpers/node'

  const props = defineProps({
    node: Object,
    requirement: Object,
  })

  const href = computed(() => {
    const route_name = NODE_TYPE_ROUTES[props.node.type_]
    return `/${route_name}/${props.node.id}`
  })

  const nodeLabel = computed(() => {
    if (props.requirement?.requirement_type == 'business_mandatory') {
      return ''
    } else if (props.requirement?.requirement_type == 'project_mandatory') {
      return ''
    } else {
      let result = NODE_TYPE_LABELS[props.node.type_]
      if (props.node.status) {
        result += ` (${props.node.status})`
      }
      return result
    }
  })
  const nodeName = computed(() => {
    if (props.requirement?.requirement_type == 'business_mandatory') {
      return "Voir l'affaire"
    } else if (props.requirement?.requirement_type == 'project_mandatory') {
      return 'Voir le dossier'
    } else {
      return props.node.name
    }
  })
</script>

<template>
  <td class="col_text">
    <a
      :href="href"
      aria-label="Aller à la page du document"
      title="Aller à la page du document"
      >{{ nodeName }} <em v-if="nodeLabel">({{ nodeLabel }})</em>
    </a>
    <span v-if="node.customer && nodeLabel">
      avec le client {{ node.customer.label }}
    </span>
  </td>
</template>
